import { reactive, ref } from 'vue';
import { cloneDeep } from 'lodash';
import { IFormParams } from './interface';
import { DEFAULT_SHARE_SETTING } from './index';

/** 默认的form参数, 具体的参数的注释看interface文件 */
const defaultFormParams: IFormParams = {
    // 活动链接设置
    link_img: DEFAULT_SHARE_SETTING.link_img,
    link_title: DEFAULT_SHARE_SETTING.link_title,
    link_desc: DEFAULT_SHARE_SETTING.link_desc
};

/**
 * @description 页面渲染表单所需的字段
 */
export const formParams = reactive<IFormParams>(cloneDeep(defaultFormParams));

/** 初始化 formParams */
export const initFormParams = () => {
    // 删除所有的属性，然后在进行深拷贝
    for (const key in formParams) {
        Reflect.deleteProperty(formParams, key);
    }
    Object.assign(formParams, cloneDeep(defaultFormParams));
};

/**
 * 设置formParams的方法。由详情获取过来的做转换
 * @param data 接口返回的data
 */
export const setShareFormParams = (data: any) => {
    Object.assign(formParams, data);
};
